import paramiko
from log import logger

# 远程主机信息
host = '192.168.51.174'
port = 22
username = 'root'
password = 'cds-china'

# 创建 SSH 客户端
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
    # 连接到远程主机
    client.connect(hostname=host, port=port, username=username, password=password)

    # 执行远程命令
    stdin, stdout, stderr = client.exec_command("dmidecode -t memory | grep Manufacturer: | uniq | sed 's/ //g' | sed 's/:/ /g' | awk '{print $2}'")

    # 输出命令执行结果
    for line in stdout:
        logger.info(line.strip())

    # 关闭连接
    client.close()

except Exception as e:
    logger.info('error: %s' % e)

